﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using webnew.Common;
namespace webnew.Systems
{
    public partial class S_roleList : ListBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            _ListTbName = "Sys_role";
            _EditSrc = "S_roleEdit.aspx";
            _DelType = DeleteType.FalseDel;//逻辑删除
            _Grdview = grdView;//主列表控件
            btnExcelVisble = false; //设置导出不可见
            
            if (!IsPostBack)
            {
                SetTitle(true, "后台管理 >> 角色管理");
               
                AspNetPager1_PageChanged(null, null);
            }
        }
        /// <summary>
        /// 重写删除事件,使删除后刷新页面;
        /// </summary>
        protected override void _Del()
        {
            //根据选中的公司ID,判断是否能删除
            if (new BLL.Sys_Role().isCanDel(GetSelecetedIDs(grdView)) == false)
            {
                ShowMsg = "角色使用中,不能删除!";
                return;
            }
            //----------系统日志model

            Model.Sys_LogInfo modelLog = new webnew.Model.Sys_LogInfo();
            modelLog.UserID = UserInfor.Id;                  //用户ID
            modelLog.IP = new BLL.Sys_Log().GetUserIP(System.Web.HttpContext.Current.Request);  //IP
            modelLog.Module = new BLL.Sys_Navigation().GetModuleName(this.GetType().BaseType.Name);   //模块名
            modelLog.CreateDate = DateTime.Now;           //创建时间

            string error = "";                   //获取错误信息

            try
            {
                base._Del();
            }
            catch (Exception e)
            {
                error = e.ToString();
            }
            finally
            {
                //添加一条系统日志
                new BLL.Sys_Log().AddSysLog(error, "删除", modelLog, "系统角色", "角色，角色名称为" + GetNames("rolename", _ListTbName));
            }
            AspNetPager1_PageChanged(null, null);
        }

        

       


        protected void btnSearch_Click(object sender, EventArgs e)
        {
            AspNetPager1_PageChanged(null, null);
        }

        /// <summary>
        /// 查询分页事件
        /// </summary>
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            string conditon = "isdel=0 and rolename like '%" + txtRoleName.Text.Trim().Replace("'", "") + "%'";
            AspNetPager1.RecordCount = new BLL.Sys_Role().GetCount(conditon);
            grdView.DataSource = new BLL.Sys_Role().GetPageList("*",conditon, grdView.PageSize, AspNetPager1.CurrentPageIndex, _ListTbName, "remark,rolename,id", true);
            grdView.DataBind();
        }

        protected void grdView_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "setRole")
            {
                Response.Redirect("S_roleSet.aspx?id=" + grdView.DataKeys[MyConvert.toInt32(e.CommandArgument)].Value);
            }
        }

        protected void grdView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //鼠标经过变色
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "GridViewMouseover(this)");
                e.Row.Attributes.Add("onmouseout", "GridViewMouseout(this)");
                e.Row.Attributes.Add("onclick", "GridViewonclick(this)");
            }
        }
    }
}
